package org.example;

import okhttp3.*;

import java.io.IOException;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException {
        System.out.println( "Client!" );

        String url = "http://localhost:8888/api/hello";

        OkHttpClient client = new OkHttpClient();

        //创建一个Request
        Request request = new Request.Builder()
                .get()
                .url(url)
                .build();

        //通过client发起请求
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String str = response.body().string();
                    System.out.println(str);
                }
            }
        });
    }
}
